package com.fejal.managed.Conversor;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import com.fejal.bean.GradeCurricular;
import com.fejal.dao.DAOFactory;

@FacesConverter(value="converteGradeCurricular", forClass=GradeCurricular.class) 
public class ConverteGradeCurricular implements Converter {

	@Override
	public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
		if (arg2.equals("0")){
			return new GradeCurricular();
		}
		GradeCurricular gradeCurricular = DAOFactory.getGradeCurricularDAO().getGradeCurricular(Integer.valueOf(arg2));
		gradeCurricular = gradeCurricular.retornaClone();
		return gradeCurricular; 
	}

	@Override
	public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
		return String.valueOf(((GradeCurricular) arg2).getCodigoGradeCurricular());
	}

}
